/*
package com.adingxiong.pm.controller;

import com.adingxiong.pm.entity.UserInfoEntity;
import com.adingxiong.pm.server.UserInfoServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.TimeUnit;


@RestController
@RequestMapping("/person")
@Api(tags = "人员管理")
public class UserInfoController {

    @Autowired
    private UserInfoServer userInfoServer;

    private RedisTemplate<String, Object> redisTemplate;

    @ApiOperation(value = "根据id查询用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", paramType = "query", required = true)
    })
    @RequestMapping(value = "/getOne", method = RequestMethod.GET)

    public UserInfoEntity getUserById(Long id) {
        String key = "user_" + id;
       */
/* ValueOperations<String, Object> valueOperations = redisTemplate.opsForValue();*//*

        //判断缓存中是否存在改key的值
        try {
            boolean haskey = redisTemplate.hasKey(key);
            if (haskey) {
                return (UserInfoEntity) valueOperations.get(key);
            } else {
                UserInfoEntity user = userInfoServer.getById(id);
                //如果查询不到就插入到缓存，持续时间为5小时
                valueOperations.set(key, user, 5, TimeUnit.HOURS);
                return user;
            }
        } catch (Exception e){
            e.printStackTrace();
            return  null;
        }

    }

    @ApiOperation(value = "查询所有的用户信息")
    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    public List<UserInfoEntity> getAll() {
        String key = "user_list";
        ListOperations<String, Object> operations = redisTemplate.opsForList();
        try {
            boolean haskey = redisTemplate.hasKey(key);
            if(haskey){
                return (List<UserInfoEntity>) operations.leftPop(key);
            }else{
                List<UserInfoEntity> list = userInfoServer.list();
                operations.leftPush(key,list);
                return list;
            }
        } catch (Exception e){
            e.printStackTrace();
            return null;
        }

    }
}
*/
